package com.wxmp.wxapi.util;

import org.apache.commons.lang.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author zzm
 * @Date 2023/8/14 17:03
 * @Version 1.0
 * @Description TODO
 */
public class VerifyUtil {

    public static boolean extract(String str,int i) {
        String pattern = "\\d+ - \\d+";
        Pattern regex = Pattern.compile(pattern);
        Matcher matcher = regex.matcher(str);

        if (matcher.find()) {
            String extractedString = matcher.group();
            String[] split = StringUtils.split(extractedString," - ");
            if (Integer.valueOf(split[0]).compareTo(i) < 1 && Integer.valueOf(split[1]).compareTo(i) > -1) {
               return true;
            }
        }
        return false;
    }

    public static int strExtract(String str) {
        String pattern = "第(\\d+)章";

        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(str);

        if (m.find()) {
            String number = m.group(1);
            return Integer.valueOf(number);
        }
        return 0;
    }
}
